namespace e2__文件合成窗体
{
    public partial class Form1 : Form
    {
        private string filePath1 = "";
        private string filePath2 = "";
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }


        

        private void selectFile1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                filePath1 = openFileDialog1.FileName;
                file1.Text = filePath1;
            }
        }

        private void selectFile2_Click(object sender, EventArgs e)
        {
            if(openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                filePath2 = openFileDialog1.FileName;
                file2.Text = filePath2;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(filePath2) || string.IsNullOrEmpty(filePath2))
                {
                    resultLab.Text = "请先选择两个文件";
                    return;
                }

                string content1 = File.ReadAllText(filePath1);
                string content2 = File.ReadAllText(filePath2);
                string mergeContent = content1 + Environment.NewLine + content2;

                string exePath = AppDomain.CurrentDomain.BaseDirectory;
                string dataDir = Path.Combine(exePath, "Data");
                Directory.CreateDirectory(dataDir);

                string newFileName = $"Merged_{DateTime.Now:yyyyMMdd_HHmmss}.txt";
                string newFilePath = Path.Combine(dataDir, newFileName);
                File.WriteAllText(newFilePath, mergeContent);

                resultLab.Text = "合并成功！";
            }
            catch (Exception ex)
            {
                resultLab.Text = "发生错误";
            }
        }
    }
}
